package com.financing.controller.invest;
import java.util.Date;

import com.financing.model.Data;
import com.financing.model.invest.ShareBenefitTemplet;
import com.financing.service.invest.ShareBenefitTempletService;
import com.financing.util.Json;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

/**
 * 分润模板控制器
 */
public class ShareBenefitTempletController extends Controller {
	private static ShareBenefitTempletService shareBenefitTemplet = new ShareBenefitTempletService();


	/**
	 * 获取分润模板记录列表
	 */
	public void list() {
		Page<ShareBenefitTemplet> p = shareBenefitTemplet.list(getParaToInt("page",1),getParaToInt("size",10),Data.flat(getParaMap()));
		renderJson(Json.ok("数据获取成功！", Data.put("page", p)));
	} 
    
	/**
	 * 分润模板编辑
	 */
	public void edit() { 
		int id = getParaToInt("id",0);
		ShareBenefitTemplet sbt = id>0 ? ShareBenefitTemplet.me.findById(id) : new ShareBenefitTemplet();
		sbt.setName(getPara("name"));
		sbt.setAgentRate(Double.valueOf(getPara("agentRate")));
		sbt.setPlatRate(Double.valueOf(getPara("platRate")));
		sbt.setType(getPara("type"));
		if(id>0 ? sbt.update() :sbt.setCreateTime(new Date()).save()){
			renderJson(Json.ok("分润信息编辑成功！")); 
		}else{
			renderJson(Json.error("分润信息编辑失败！"));
		}
	}	
	 
	/**
	 * 查看分润模板信息
	 */
	public void info() { 
		ShareBenefitTemplet b = ShareBenefitTemplet.me.findById(getParaToInt("id",0));
		renderJson(Json.ok("数据获取成功！", Data.put("item",b)));
	}	
	
	/**
	 * 分润模板信息删除
	 */
	public void del() {
		ShareBenefitTemplet sbt = ShareBenefitTemplet.me.findById(getParaToInt("id",0));
		if(sbt!=null){
			sbt.delete();
			renderJson(Json.ok("删除成功！"));
		}
	}
}
 